package com.technology.reflectation;

public class AnnotationHandler {

	public static void main(String[] args) {
		inspectService(ClassUsing.class);
		inspectService(CarReflection.class);
		inspectService(Integer.class);
	}

	static void inspectService(Class<?> cl){
		if (cl.isAnnotationPresent(Service.class)){
			Service service = cl.getAnnotation(Service.class);
			System.out.println(service.name());
			System.out.println(service.lazyLoaded());
			
			if (!service.lazyLoaded()){
				try {
					Object obj = cl.newInstance();
					if (obj instanceof ClassUsing){
						((ClassUsing) obj).helloWorld();
					}
				} catch (InstantiationException | IllegalAccessException e) {
					e.printStackTrace();
				}
			}
		}
		else {
			System.out.println(cl.getCanonicalName() + " has no such annotations");
		}
	}
}
